import { Space, Popconfirm, Button } from 'antd';
import ProTableComp, { type ColumnsType, type ToolsType } from '@/components/ProTableComp';
import { adminUserList } from '@/api/modules/adminUser';

import "./index.less";

const Page = () => {
	const columns: ColumnsType[] = [{
		title: '用户昵称',
		dataIndex: 'nick_name',
		width: '180',
		valueType: 'text',
	}, {
		title: '用户手机',
		dataIndex: 'mobile',
		width: '180',
		valueType: 'text',
	}, {
		title: '用户角色',
		dataIndex: 'role',
		render: (val: any) => {
			if (val && val.length) {
				return val.map((item: any) => item.name).join(",");
			}
			return '-';
		},
	}, {
		title: '账号类型',
		dataIndex: 'type',
		hideSearch: true,
		width: '180',
		valueEnum: () => {
			return {
				1: { text: '管理员', displayType: 'button', props: { type: 'primary' } },
				2: { text: '普通用户', status: 'cyan' },
			}
		},
	}, {
		title: '账号状态',
		dataIndex: 'status',
		valueType: 'select',
		width: '180',
		valueEnum: () => {
			return {
				1: { text: '开启', status: 'green' },
				2: { text: '禁用', status: 'red' },
			}
		},
	}, {
		title: '最近登录时间',
		dataIndex: 'last_login_time',
		width: '180',
		hideSearch: true,
	}, {
		title: '创建时间',
		dataIndex: 'create_time',
		width: '180',
		hideSearch: true,
	}, {
		title: '操作',
		dataIndex: 'h',
		hideSearch: true,
		width: '180',
		fixed: 'right',
		render: (_, record) => (
			<Space>
				<Button type="primary">编辑</Button>
				<Popconfirm
					title="确定删除吗?"
					onConfirm={() => {
						console.log(record);
					}}
				/>
			</Space>
		)
	}];

	const tools: ToolsType[] = [
		{
			type: 'button',
			text: '新增',
			compProps: {
				type: 'primary',
				onClick: () => {
					console.log('新增');
				}
			}
		}
	];

	return (
		<div className="card content-box admin-user">
			<ProTableComp
				tableName="用户管理"
				request={adminUserList}
				columns={columns}
				tools={tools}
			/>
		</div>
	);
};

export default Page;
